using System;
using System.Collections;
using System.Text;
using AllegNet;

namespace DemonHunter
{
    class PlayerCharacter : Entity
    {
        private static PlayerCharacter me;
        private static Bmp curBitmap;
        private static Bmp myBitmap;
        private static Bmp attackBitmap;

        private int grenades = 20;
        private int ammo = 50;

        private bool attacking = false;
        private DateTime gunAttackStart;

        public int GetGrenades() { return grenades; }
        public int GetAmmo() { return ammo; }
        public int GetHealth() { return health; }

        public PlayerCharacter()
        {
            me = this;

            health = 100;
            killable = true;

            entityYLoc = 480;
            entityXLoc = 1024 / 2 - 30;
        }

        private void VerifyOnScreen()
        {
            double xLoc = Logic.GetInstance().GetXLoc();
            if (entityXLoc < xLoc) entityXLoc = xLoc;
            if (entityXLoc + myBitmap.Width > xLoc + 1024) entityXLoc = xLoc + 1024 - myBitmap.Width;
        }

        public void DropGrenade()
        {
            Grenade grenade = new Grenade();
            Level.GetInstance().AddEntity(grenade);
            grenades--;
        }

        // do not allow AI to move player
        public override void move() { }

        public override void animate()
        {
            if (attacking == true)
            {
                DateTime stop = DateTime.Now;
                TimeSpan elapsed = stop - gunAttackStart;
                if (elapsed.Milliseconds > 400)
                {
                    attacking = false;
                    curBitmap = myBitmap;
                }
            }
        }
        
        public override Bmp GetCurrentBitmap()
        {
            return curBitmap;
        }
        public new static void LoadBitmaps()
        {
            myBitmap = Game.GetInstance().LoadBitmap("C:\\DemonHunterart\\hero\\herogun.bmp");
            attackBitmap = Game.GetInstance().LoadBitmap("C:\\DemonHunterart\\hero\\herogunflash.bmp");
            curBitmap = myBitmap;
        }

        public static PlayerCharacter GetInstance() { return me; }

        public override void DoXIncrease() 
        {
            entityXLoc += 4 * speedModifier;
            VerifyOnScreen();
        }
        public void Attack()
        {
            Sound.playSound(Sound.SOUND_GUN);
            gunAttackStart = DateTime.Now;
            attacking = true;
            curBitmap = attackBitmap;
            ammo--;
        }

        public override void ReduceHealth(int amt)
        {
            base.ReduceHealth(amt);
            UI.GetInstance().Refresh();
        }

        public override double GetCurrentBitmapHeight()
        {
            return myBitmap.Height;
        }

        protected override void KillMe()
        {
        }
    }
}
